﻿Imports System.Data.SqlClient

Public Class Djuridicas
    Inherits Conexion
    Dim cmd As SqlCommand

    Public Function guardarjuridicas(ByVal dts As Entidades.Ejuridicas) As Boolean
        Try
            conectado()

            cmd = New SqlCommand("agregar_juridicas")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@fecha_alta", dts.fechaalta)
            cmd.Parameters.AddWithValue("@denominacion", dts.apenom)
            cmd.Parameters.AddWithValue("@num_cuit", dts.numcuit)
            cmd.Parameters.AddWithValue("@telfijo", dts.telfijo)
            cmd.Parameters.AddWithValue("@telmovil", dts.telmovil)
            cmd.Parameters.AddWithValue("@provincia", dts.provin)
            cmd.Parameters.AddWithValue("@departamento", dts.dep)
            cmd.Parameters.AddWithValue("@localidad", dts.loc)
            cmd.Parameters.AddWithValue("@cod_postal", dts.codpostal)
            cmd.Parameters.AddWithValue("@domlegal", dts.domlegal)
            cmd.Parameters.AddWithValue("@numlegal", dts.numlegal)
            cmd.Parameters.AddWithValue("@pisolegal", dts.pisolegal)
            cmd.Parameters.AddWithValue("@dptolegal", dts.dptolegal)
            cmd.Parameters.AddWithValue("@domreal", dts.domreal)
            cmd.Parameters.AddWithValue("@numreal", dts.numreal)
            cmd.Parameters.AddWithValue("@pisoreal", dts.pisoreal)
            cmd.Parameters.AddWithValue("@dptoreal", dts.dptoreal)

            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()
        End Try
    End Function

    Public Function modificarperjuridicas(ByVal dts As Entidades.Ejuridicas) As Boolean
        Try
            conectado()

            cmd = New SqlCommand("sp_modificarjuridicas")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@fecha_alta", dts.fechaalta)
            cmd.Parameters.AddWithValue("@ape_nom", dts.apenom)
            cmd.Parameters.AddWithValue("@num_cuit", dts.numcuit)
            cmd.Parameters.AddWithValue("@telfijo", dts.telfijo)
            cmd.Parameters.AddWithValue("@telmovil", dts.telmovil)
            cmd.Parameters.AddWithValue("@provincia", dts.provin)
            cmd.Parameters.AddWithValue("@departamento", dts.dep)
            cmd.Parameters.AddWithValue("@localidad", dts.loc)
            cmd.Parameters.AddWithValue("@cod_postal", dts.codpostal)
            cmd.Parameters.AddWithValue("@domlegal", dts.domlegal)
            cmd.Parameters.AddWithValue("@numlegal", dts.numlegal)
            cmd.Parameters.AddWithValue("@pisolegal", dts.pisolegal)
            cmd.Parameters.AddWithValue("@dptolegal", dts.dptolegal)
            cmd.Parameters.AddWithValue("@domlegal", dts.domreal)
            cmd.Parameters.AddWithValue("@numlegal", dts.numreal)
            cmd.Parameters.AddWithValue("@pisolegal", dts.pisoreal)
            cmd.Parameters.AddWithValue("@dptolegal", dts.dptoreal)
            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()
        End Try
    End Function

    Public Function eliminarperjuridicas(ByVal dts As Entidades.Ejuridicas) As Boolean
        Try
            conectado()
            cmd = New SqlCommand("sp_eliminarjuridicas")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@num_cuit", dts.numcuit)

            If cmd.ExecuteNonQuery Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        Finally
            desconectado()
        End Try
    End Function
    
    Public Function llenarcomboprovin() As DataTable
        Try
            conectado()

            cmd = New SqlCommand("sp_provincia")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

    Public Function llenarcombodepartamento(ByVal DEPARTAMENTO As String) As DataTable
        Try
            conectado()

            cmd = New SqlCommand("sp_combodepartamento")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@nombre_provincia", DEPARTAMENTO)

            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

    Public Function llenarcombolocalidad(ByVal DEPARTAMENTO As String) As DataTable
        Try
            conectado()

            cmd = New SqlCommand("sp_combolocalidad")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@nombre_departamento", DEPARTAMENTO)

            Dim DA As New SqlDataAdapter(cmd)
            Dim TABLA As New DataTable
            TABLA.Clear()
            DA.Fill(TABLA)
            Return TABLA
            Return Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

    Public Function buscarjuridicas(ByVal LISTA As String) As DataTable

        Try

            conectado()

            cmd = New SqlCommand("sp_buscarjuridica")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            cmd.Parameters.AddWithValue("@num_cuit", LISTA)

            Dim DA As New SqlDataAdapter(cmd)
            Dim tabla As New DataTable
            tabla.Clear()
            DA.Fill(tabla)
            Return tabla

            Return Nothing

        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

    Public Function buscartodos() As DataTable

        Try

            conectado()

            cmd = New SqlCommand("sp_verjuridicas")
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Connection = cnn

            Dim DA As New SqlDataAdapter(cmd)
            Dim tabla As New DataTable
            tabla.Clear()
            DA.Fill(tabla)
            Return tabla

            Return Nothing

        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        Finally
            desconectado()
        End Try
    End Function

End Class
